﻿namespace WMS.FC.Domain.DomainObject.System
{
    /// <summary>
    /// 操作结果
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ActionResult<T> : ActionResultBase
    {
        /// <summary>
        /// 数据
        /// </summary>
        public T? Data { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="actionDescription"></param>
        public ActionResult(string? actionDescription = null) : base(actionDescription)
        {
        }

        /// <summary>
        /// 部分成功
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public new ActionResult<T> PartSuccess(string message)
        {
            ErrorCode = ErrorCode.E001;
            Message = message;
            return this;
        }

        /// <summary>
        /// 程序异常
        /// </summary>
        /// <param name="ex"></param>
        /// <returns></returns>
        public new ActionResult<T> Exception(Exception ex)
        {
            ErrorCode = ErrorCode.E006;
            Message = $"{actionFailDescription}{ex.Message}";
            return this;
        }

        /// <summary>
        /// 参数校验不通过
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public new ActionResult<T> ArgumentError(string message)
        {
            ErrorCode = ErrorCode.E003;
            Message = $"{actionFailDescription}{message}";
            return this;
        }

        /// <summary>
        /// 业务校验不通过
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public new ActionResult<T> BusinessError(string message)
        {
            ErrorCode = ErrorCode.E004;
            Message = $"{actionFailDescription}{message}";
            return this;
        }

        /// <summary>
        /// 数据库执行异常
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public new ActionResult<T> DbError(string message)
        {
            ErrorCode = ErrorCode.E005;
            Message = $"{actionFailDescription}{message}";
            return this;
        }

        /// <summary>
        /// 调用服务失败
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public new ActionResult<T> Fail(ActionResultBase result)
        {
            ErrorCode = result.ErrorCode;
            Message = $"{actionFailDescription}{result.Message}";
            return this;
        }
    }
}
